package com.hl.controller.orders;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.hl.domain.PaymentRecord;
import com.hl.service.IPaymentRecordService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 收款记录Controller
 * 
 * @author ruoyi
 * @date 2025-08-08
 */
@RestController
@RequestMapping("/payment")
public class PaymentRecordController extends BaseController
{
    @Autowired
    private IPaymentRecordService paymentRecordService;

    /**
     * 查询收款记录列表
     */
    @RequiresPermissions("orders:payment:list")
    @GetMapping("/list")
    public TableDataInfo list(PaymentRecord paymentRecord)
    {
        startPage();
        List<PaymentRecord> list = paymentRecordService.selectPaymentRecordList(paymentRecord);
        return getDataTable(list);
    }

    /**
     * 导出收款记录列表
     */
    @RequiresPermissions("orders:payment:export")
    @Log(title = "收款记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PaymentRecord paymentRecord)
    {
        List<PaymentRecord> list = paymentRecordService.selectPaymentRecordList(paymentRecord);
        ExcelUtil<PaymentRecord> util = new ExcelUtil<PaymentRecord>(PaymentRecord.class);
        util.exportExcel(response, list, "收款记录数据");
    }

    /**
     * 获取收款记录详细信息
     */
    @RequiresPermissions("orders:payment:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(paymentRecordService.selectPaymentRecordById(id));
    }

    /**
     * 新增收款记录
     */
    @RequiresPermissions("orders:payment:add")
    @Log(title = "收款记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PaymentRecord paymentRecord)
    {
        return toAjax(paymentRecordService.insertPaymentRecord(paymentRecord));
    }

    /**
     * 修改收款记录
     */
    @RequiresPermissions("orders:payment:edit")
    @Log(title = "收款记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PaymentRecord paymentRecord)
    {
        return toAjax(paymentRecordService.updatePaymentRecord(paymentRecord));
    }

    /**
     * 删除收款记录
     */
    @RequiresPermissions("orders:payment:remove")
    @Log(title = "收款记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(paymentRecordService.deletePaymentRecordByIds(ids));
    }

    /**
     * 获取支付状态选项
     */
    @GetMapping("/paymentStatusOptions")
    public AjaxResult getPaymentStatusOptions()
    {
        return success(paymentRecordService.getPaymentStatusOptions());
    }

    /**
     * 获取支付方式选项
     */
    @GetMapping("/paymentMethodOptions")
    public AjaxResult getPaymentMethodOptions()
    {
        return success(paymentRecordService.getPaymentMethodOptions());
    }

    /**
     * 根据订单号查询支付记录
     */
    @GetMapping("/getByOrderId/{orderId}")
    public AjaxResult getByOrderId(@PathVariable("orderId") String orderId)
    {
        return success(paymentRecordService.selectPaymentRecordByOrderId(orderId));
    }
}
